﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Bidder_BidProductAndCompany : System.Web.UI.Page
{
    public string BId;
    string ProjectId = "";
    protected void Page_Load(object sender, EventArgs e)
    {

        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCompany);
        ProjectId = SysFun.IsSQL(SysFun.ToTrim(Request.QueryString["projectid"]));

        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
           
            showGridView();
        }
    }

    
    public void showGridView()
    {
        int i = 0;
        string strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "bidgoods_view";                                               //要查询的表明
        dbPage.Key = "bidid";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = "MEMO8,factoryusercode,MEMO9,bidid,goodsid,ProductName,Outlookc,UserCode_TB,Factor,Medicinemodel,Unit,ProductCode,salername,factoryname,goodsName,case  when CheckStatus is   null then '未审核' when CheckStatus='0' then '未审核'  when CheckStatus='1' then '审核通过' when CheckStatus='2' then '不通过'   when CheckStatus='3' then '废标' when CheckStatus='4' then '超过限价废标' when CheckStatus='5' then '竞价废标' else '未知' end  as CheckStatus";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 20;                                                    //没有显示记录条数   
        dbPage.OrderBy = "factoryname,productname,medicinemodel,outlookc,bidid";//排序字段


        System.Text.StringBuilder strHtml = new System.Text.StringBuilder();
        strHtml.Append("<table width='98%' border='0' align='center' cellpadding='2' cellspacing='1' class='table_table'>");
        strHtml.Append("<tr>");
        strHtml.Append("<td class='table_title' nowrap>流水号</td>");
        strHtml.Append("<td class='table_title' nowrap>注册号</td>");
        strHtml.Append("<td class='table_title' nowrap>投标人</td>");
        strHtml.Append("<td class='table_title' nowrap>品目号</td>");
        strHtml.Append("<td class='table_title' nowrap>通用名</td>");
        strHtml.Append("<td class='table_title' nowrap>规格</td>");
        strHtml.Append("<td class='table_title' nowrap>剂型</td>");
        strHtml.Append("<td class='table_title' nowrap>转换系数</td>");
        strHtml.Append("<td class='table_title' nowrap>生产厂家</td>");
        strHtml.Append("<td class='table_title' nowrap>注册号</td>");
        strHtml.Append("<td class='table_title' nowrap>审核状态</td>");
        strHtml.Append("</tr>");
        System.Data.IDataReader dr = dbPage.ExecuteReader();

        while (dr.Read())
        {
            string _strCheckStatus = dr["CheckStatus"].ToString();
            if (_strCheckStatus == "不通过")
            {
                strHtml.Append("<tr style='background-color:Yellow'>");
            }
            else
            {
                if (i == 0)
                {
                    strHtml.Append("<tr class='table_td'>");
                    i++;
                }
                else
                {
                    strHtml.Append("<tr class='table_td2'>");
                    i--;
                }
            }

            strHtml.Append("<td>" + dr["goodsid"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["UserCode_TB"].ToString() + "</td>");
            strHtml.Append("<td><input type='hidden' name='AccountId' value='" + dr["bidid"].ToString() + "'>" + dr["salername"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["ProductCode"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["ProductName"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["Outlookc"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["Medicinemodel"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["Factor"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["factoryname"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["factoryusercode"].ToString() + "</td>");
            strHtml.Append("<td title='" + dr["MEMO9"].ToString() + "'>" + _strCheckStatus + "</td>");
            strHtml.Append("</tr>");
        }
        strHtml.Append("</table>");
        Label1.Text = strHtml.ToString();

        //BId = Request.Form["bidid"].ToString();
        //GridView1.DataSource = dr;
        //GridView1.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();

        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键



    }

    /// <summary>
    /// 生成查询条件
    /// </summary>
    /// <returns></returns>
    public string fctConditions()
    {
        
        string ProjectId = SysFun.IsSQL(SysFun.ToTrim(Request.QueryString["projectid"]));

        string strtemp = " bidgoods_view.projectid=" + ProjectId + "  and";
         HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        // strtemp += " goodsid in (select goodsid from project_bid where  goodsid in (select goodsid from project_bid where  projectid=" + ProjectId + "  and  accountid=" + _Account.AccountId + ")  group by  goodsid having count(*)>1 ) and";
         strtemp += " productname+convert(varchar(255),accountid_sc) in (select productname+convert(varchar(255),goods.accountid_sc) as ProductNameAndAccountId_SC from product ,goods,project_bid where product.productid=goods.productid and goods.goodsid=project_bid.goodsid and projectid=" + ProjectId + " and Goods.goodsid in (select goodsid from project_bid where  projectid=" + ProjectId + "  and  accountid=" + _Account.AccountId + ")  group by productname+convert(varchar(255),goods.accountid_sc) having max(project_bid.Accountid)<>min(project_bid.Accountid)) and";

        //药品流水号
        string _strGoodsId = SysFun.ToTrim(txtGoodsId.Text);
        if (_strGoodsId != "")
        {
            strtemp += " GoodsId like '%" + _strGoodsId + "%' and";

        }
        //品目号
        string _strProductCode = txtProductCode.Text.ToString();
        if (_strProductCode != "")
        {
            strtemp += " productcode like '%" + _strProductCode + "%' and";

        }
        //通用码
        string _strProductName = txtProductName.Text.ToString();
        if (_strProductName != "")
        {
            strtemp += " (ProductName like '%" + _strProductName + "%'or SpellingCode like '%" + _strProductName + "%') and";
        }
        //规格
        string _strOutlookc = txtOutlookc.Text.ToString();
        if (_strOutlookc != "")
        {
            strtemp += " outlookc like '%" + _strOutlookc + "%' and";
        }
        //生产企业注册号
        string _strUserCode_SC = txtUserCode_SC.Text.ToString();
        if (_strUserCode_SC != "") //按生产企业注册号查询
        {
            strtemp += " factoryusercode like '%" + _strUserCode_SC + "%' and";
        }

        //生产企业名称
        string _strCompanyName = txtCompanyName_SC.Text.ToString();
        if (_strCompanyName != "")
        {
            strtemp += " factoryname like '%" + _strCompanyName + "%' and";

        }

        if (strtemp != "")
        {
            strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }

        return strtemp;

    }



    protected void Button5_Click(object sender, EventArgs e)
    {

    }
}
